"use server";
import Title from "antd/es/typography/Title";
import { Divider, Flex, message } from "antd";
import "./index.css";
import {listQuestionVoByPageUsingPost, searchQuestionVoByPageUsingPost} from "@/api/questionController";
import QuestionTable from "@/components/QuestionTable";

/**
 * 主页
 * @constructor
 */
export default async function QuestionPage({ searchParams }) {
  //  获取url的查询参数
  const { q: searchText } = searchParams;
  let questionList = [];
  let total = 0;
  try {
    const result = await searchQuestionVoByPageUsingPost({
      searchText,
      pageSize: 12,
      sortField: "createTime",
      sortOrder: "descend",
    });
    questionList = result.data.records ?? [];
    total = result.data.total;
  } catch (e) {
    message.error("获取题目列表失败，" + e.message);
  }

  return (
    <div id="questionsPage" className={"max-width-content"}>
      <Title level={3}>
        <Flex justify="space-between" align="center">
          <Title level={3}>全部题目</Title>
        </Flex>
      </Title>
      <QuestionTable
        defaultQuestionList={questionList}
        defaultTotal={total}
        defaultSearchParams={{
          title: searchText,
        }}
      ></QuestionTable>
      <Divider />
    </div>
  );
}

